package com.macro.mall.portal.controller.ums;

import com.github.pagehelper.Page;
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.controller.BaseController;
import com.macro.mall.portal.dto.ums.PagedQueryFansReqDto;
import com.macro.mall.ums.domain.Member;
import com.macro.mall.ums.entity.MemberEntity;
import com.macro.mall.ums.service.account.MemberService;
import com.macro.mall.ums.service.account.bo.PagedQueryMemberInput;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * class
 *
 * @author xuyanjun
 * @date 2019-12-23
 */
@Api(tags = "FansController", description = "粉丝信息管理")
@Slf4j(topic = "FansController")
@RestController
public class FansController extends BaseController {

    @Autowired
    private MemberService memberService;

    /**
     * 分页查询粉丝
     *
     * @return 分页后的会员
     */
    @ApiOperation("分页查询会员")
    @PostMapping("pagedQuery")
    public CommonPage<Member> pagedQuery(@RequestBody PagedQueryFansReqDto reqDto) {
        final UmsMember currentUser = getCurrentUser();

        PagedQueryMemberInput pagedQueryFansInput = new PagedQueryMemberInput();
        pagedQueryFansInput
                .setBefId(currentUser.getId())
                .setPageIndex(reqDto.getPageIndex())
                .setPageSize(reqDto.getPageSize());

        Page<MemberEntity> page = memberService.pagedQuery(pagedQueryFansInput);
        final List<Member> members = memberService.entityToDomain(page);

        return CommonPage.restPage(members, page);
    }
}
